'''
由于Algebraic的运算规则与目前使用的基础运算规则相同，所以直接引用
'''
import os
from Utilities.AutoGetOperator.selectPackage import get_func

Operator_IVQ_ROFS=get_func(r'Operators/OperationOperators/OperatorIVQROF.py','Operator_IVQ_ROFS')

class A(Operator_IVQ_ROFS):

    def getResult(self):
        '''
        function：基础的算数平均公式
        :return: AA公式计算的结果
        '''
        result=self.data_list[0]
        for i in range(1,len(self.data_list)):
            result=self.add(result,self.data_list[i])
        result=self.kmulti(result,1/len(self.data_list))

        return result

class GA(Operator_IVQ_ROFS):

    def getResult(self):
        '''
        function：基础的算数平均公式
        :return: AA公式计算的结果
        '''
        result = self.data_list[0]
        for i in range(1, len(self.data_list)):
            result = self.multi(result, self.data_list[i])
        result = self.pow(result, 1 / len(self.data_list))

        return result

class WA(Operator_IVQ_ROFS):

    def getResult(self):
        '''
        function：基础的加权算数平均公式
        :return: WAA公式计算的结果
        '''
        result = self.kmulti(self.data_list[0],self.weight_list[0])
        for i in range(1, len(self.data_list)):
            temp=self.kmulti(self.data_list[i],self.weight_list[i])
            result = self.add(result, temp)

        return result

class WGA(Operator_IVQ_ROFS):

    def getResult(self):
        '''
        function：基础的加权几何平均公式
        :return: WAA公式计算的结果
        '''
        result = self.pow(self.data_list[0],self.weight_list[0])
        for i in range(1, len(self.data_list)):
            temp=self.pow(self.data_list[i],self.weight_list[i])
            result = self.multi(result, temp)

        return result

class OWA(Operator_IVQ_ROFS):

    def getResult(self):
        '''
        function：基础的有序加权算数平均公式
        :return: OWAA公式计算的结果
        '''
        # 将 数据集备份，将类中数据集属性 替换为 排序后的数据集
        data_list = self.data_list
        self.data_list = self.sortdata()

        result = self.kmulti(self.data_list[0],self.weight_list[0])
        for i in range(1, len(self.data_list)):
            temp=self.kmulti(self.data_list[i],self.weight_list[i])
            result = self.add(result, temp)

        # 还原数据集
        self.data_list = data_list
        return result


if __name__ == "__main__":
    data= [([0.85, 0.95], [0.1, 0.2]), ([0.8, 0.9], [0.1, 0.2]), ([0.85, 0.95], [0.1, 0.2]), ([0.7, 0.8], [0.2, 0.3]),
        ([0.4, 0.5], [0.5, 0.6])]
    li=[([0.7,0.9],[0.3,0.5]),([0.3,0.4],[0.5,0.6]),([0.5,0.6],[0.4,0.5])]
    li2=[0.4,0.4,0.2]
    a=WA(li,li2,3).getResult()
    print(a)
    weight_list = [0.1, 0.2, 0.3, 0.1, 0.3]
    result  = GA(data)
    # print(result.getResult())